<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-button v-if="isAuth('member_group:v9membergroup:save')" type="primary" @click="addOrUpdateHandle()">添加会员组</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="groupid"
        header-align="center"
        align="center"
        label="ID">
      </el-table-column>
      <el-table-column
        prop="sort"
        header-align="center"
        align="center"
        width="80"
        label="排序">
        <template slot-scope="scope">
          <el-input
            align="center"
            class="input-new-tag order"
            v-model="scope.row.sort"
            size="small"
            @keyup.enter.native="handleInputConfirm(scope.row.groupid,scope.row.sort)"
          >
          </el-input>
        </template>
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="用户组名">
      </el-table-column>
      <el-table-column
        prop="issystem"
        header-align="center"
        align="center"
        label="系统组">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.issystem == 1" size="small" >√</el-tag>
          <el-tag type="danger" v-if="scope.row.issystem == 0" size="small" >×</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="starnum"
        header-align="center"
        align="center"
        label="星星数">
      </el-table-column>
      <el-table-column
        prop="point"
        header-align="center"
        align="center"
        label="积分小于">
      </el-table-column>
      <el-table-column
        prop="allowvisit"
        header-align="center"
        align="center"
        label="允许上传附件">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.allowvisit == 1" size="small" >√</el-tag>
          <el-tag type="danger" v-if="scope.row.allowvisit == 0" size="small" >×</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="allowpost"
        header-align="center"
        align="center"
        label="投稿权限">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.allowpost == 1" size="small" >√</el-tag>
          <el-tag type="danger" v-if="scope.row.allowpost == 0" size="small" >×</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="allowpostverify"
        header-align="center"
        align="center"
        label="投稿不需审核">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.allowpostverify == 1" size="small" >√</el-tag>
          <el-tag type="danger" v-if="scope.row.allowpostverify == 0" size="small" >×</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="allowpost"
        header-align="center"
        align="center"
        label="搜索权限">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.allowpost == 1" size="small" >√</el-tag>
          <el-tag type="danger" v-if="scope.row.allowpost == 0" size="small" >×</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="allowupgrade"
        header-align="center"
        align="center"
        label="自助升级">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.allowupgrade == 1" size="small" >√</el-tag>
          <el-tag type="danger" v-if="scope.row.allowupgrade == 0" size="small" >×</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="allowsendmessage"
        header-align="center"
        align="center"
        label="发短消息">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.allowsendmessage == 1" size="small" >√</el-tag>
          <el-tag type="danger" v-if="scope.row.allowsendmessage == 0" size="small" >×</el-tag>
        </template>
      </el-table-column>

      <!--<el-table-column
        prop="moneyText"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowmessage"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowvisit"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowpost"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowpostverify"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowsearch"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowupgrade"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowsendmessage"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowpostnum"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="allowattachment"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="priceY"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="priceM"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="priceD"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="icon"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="usernamecolor"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="description"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="disabled"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="jifendikou"
        header-align="center"
        align="center"
        label="积分扣减金额">
      </el-table-column>
      <el-table-column
        prop="discount"
        header-align="center"
        align="center"
        label="运费折扣">
      </el-table-column>
      <el-table-column
        prop="yhq"
        header-align="center"
        align="center"
        label="优惠券">
      </el-table-column>
      <el-table-column
        prop="finePhoto"
        header-align="center"
        align="center"
        label="精细拍照">
      </el-table-column>
      <el-table-column
        prop="freeStorage"
        header-align="center"
        align="center"
        label="免费仓储天数">
      </el-table-column>
      <el-table-column
        prop="exchangePurchase"
        header-align="center"
        align="center"
        label="国内退换货服务">
      </el-table-column>
      <el-table-column
        prop="brokeragePerCentum"
        header-align="center"
        align="center"
        label="佣金比例">
      </el-table-column>
      <el-table-column
        prop="money"
        header-align="center"
        align="center"
        label="">
      </el-table-column>
      <el-table-column
        prop="pointText"
        header-align="center"
        align="center"
        label="积分文字说明">
      </el-table-column>
      <el-table-column
        prop="discountText"
        header-align="center"
        align="center"
        label="折扣文字说明">
      </el-table-column>
      <el-table-column
        prop="yhqText"
        header-align="center"
        align="center"
        label="优惠券文字说明">
      </el-table-column>-->
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.groupid)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './v9membergroup-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      handleInputConfirm(id,val) {
        if(val>=0){
          this.$http({
            url: this.$http.adornUrl('/member_group/v9memberGroup/setorder'),
            method: 'get',
            params: this.$http.adornParams({
              'groupid': id,
              'sort':val
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/member_group/v9membergroup/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.groupid
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/member_group/v9membergroup/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
<style lang="scss">
  .member_group .order .el-input__inner{
    text-align: center;
  }
</style>
